package com.ryan.dispatcher.comp;

import com.ryan.dispatcher.ResourceTable;
import com.ryan.ohos.extension.FractionManageHelper;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

public class PagerFraction extends Fraction {

    private final int index;

    public PagerFraction(int index) {
        this.index = index;
    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        return scatter.parse(ResourceTable.Layout_item_pager, null, false);
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);

        Text text = (Text) getComponent().findComponentById(ResourceTable.Id_item_text);
        text.setText("text" + index);

        text.setClickedListener(v -> {
            FractionManageHelper.submit(getFractionAbility().getFractionManager());
        });

//        Component component = getComponent().findComponentById(ResourceTable.Id_fraction_container);
//        component.setId(component.hashCode());

    }
}
